package org.teststack.Api.Sl.MCcc;

import com.jayway.restassured.RestAssured;
import com.jayway.restassured.response.Response;
import org.apache.commons.codec.net.URLCodec;
import org.teststack.Api.RestClient;
import org.teststack.utils.ConMysql;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.sql.ResultSet;
import java.sql.SQLException;

import static org.teststack.Api.CookieManager.cookies;


public class McccApi1 {//名称查重

    public static void main(String[] args) throws UnsupportedEncodingException, SQLException, ClassNotFoundException {
        mcccApi();
    }
    public static int mcccApi() throws UnsupportedEncodingException, SQLException, ClassNotFoundException {
        // 登录并更新cookies
        RestClient.loginAndUpdateCookies("liutao", "xQ5Vea/L3CMRNEwoBESSZGSVCnValY4kZcAYe3153B9/dXpazZRG8VLEuMhJdW1RhdZ/cqdUq/5FUdAxeKzdWOmZEj0sVlobwrqzRMgrIPsvyp03QTktVYRUAgloA924e5wLLSx8ECJ4WpUAB8zUa41GkyURFmyVtwxQ3EkLuabQ7V24L8EdzRfBHnFd8zRRd4RkncACXO88rrb4U7uR10ANvR0K4N2Kiai901pyztSuMfXP0fVRBW1lKj+kIONtFufTZoAL48++Q6VVr3r5B9tIC4kkwv0WzQxeOubbVKTNUi1JGnS2CEPPqjuXWJnUAO3u5PRxXmtH5+JN8yXygw==");

//        String nameid = null;
//        String select_sql = "select * from QCDZ_MC_SL_MCBYJL where  entname like '%浙江非脚后跟建筑设计事务所有限责任公司%'";
//        ResultSet resultSet = ConMysql.exec_select(select_sql);
//        while (resultSet.next()) {
//
//            nameid = resultSet.getString("name_id");
//            System.out.println("nameid: " + nameid);
//        }

        String nameXzqh = "浙江";
        String nameZh = "非脚后跟";
        String nameHy = "建筑设计事务所";
        String nameZzxs = "有限责任公司";
        String tradpiny = "有限责任公司";
        String nameQc = "浙江非脚后跟建筑设计事务所有限责任公司";
        String S_PROLOC = "浙江省杭州市上城区笕桥街道";
        String S_NAME = "建筑";
        String zyyw = "工程设计活动";
//        URLCodec urlCodec = new URLCodec();
//        String encodedParam = URLEncoder.encode(nameXzqh, "GBK");
//        String encodedParam1 = URLEncoder.encode(nameZh, "GBK");
//        String encodedParam2 = URLEncoder.encode(nameHy, "GBK");
//        String encodedParam3 = URLEncoder.encode(nameZzxs, "GBK");
//        String encodedParam4 = URLEncoder.encode(nameQc, "GBK");
//        String encodedParam5 = URLEncoder.encode(S_PROLOC, "GBK");
//        String encodedParam6 = URLEncoder.encode(S_NAME, "GBK");
//        String encodedParam7 = URLEncoder.encode(zyyw, "GBK");
//        String formData = "/ywtSldj.do?method=edit&csrftoken=&nameXzqh=" + encodedParam +"&nameHhlx=&nameZh=" + encodedParam1 +"&nameHy=" +encodedParam2 + "&nameZzxs=" + encodedParam3 + "&nameQc=" +encodedParam4 + "&nameList=&mcjbxx=&sbid=&name_id=&pripid=&basemcclsm=&clidsm=&S_PROLOC_PROVINCE=330000&S_PROLOC_CITY=330100&S_PROLOC_DISTRICT=330102&S_PROLOC_STREET=330102016&S_PROLOC_LOCATION=&S_PROLOC=" + encodedParam5 + "&S_QYZTLX=01&S_REGCAP=&S_MCZZXS="+ encodedParam3 +"&S_QYLXDL=11&S_ENTTYPE=1100&S_ZCZJ=&S_RJCZE=&S_CZE=&S_SJQYENTNAME=&S_SJQYUNISCID=&S_COMMITLETTER=&S_ZZSIGN=hz&S_GMLX=0&S_TRADPINY=ELABOBANDAO&S_MCHYSIGN=1&S_HYDL=M&S_HYZL=7400&S_HYXL=7484&S_ISPCOM=2&S_ISQZSP=undefined&xzqh=" + encodedParam + "&mchy=" +encodedParam2+  "&zzxs=" +encodedParam3 + "&zyyw="   +   encodedParam7 + "&xzqhwz=0&sbms=1&ljmsign=&znspsign=0&thsign=&ghcomboid=&ghopscope=&gzqsign=&pri_pripid=&zrzysx=&qylx=qy&gtscmc=&zwzh=" + encodedParam1 + "&S_NAME=" + encodedParam6 + "&zzxs-qylx-nwz=nz&zzxs-qylx=yx&wzmc=1&S_ITENAME=&S_ITEREGNO=&csrftoken=";

String formData = "/ywtSldj.do?method=edit&name_id=202408191259317204036&pripid=&sbid=&tradpiny=FEIJIAOHOUGEN&select_mkid=1&csrftoken=&sbms=1&S_PROLOC=%25E6%25B5%2599%25E6%25B1%259F%25E7%259C%2581%25E6%259D%25AD%25E5%25B7%259E%25E5%25B8%2582%25E4%25B8%258A%25E5%259F%258E%25E5%258C%25BA%25E7%25AC%2595%25E6%25A1%25A5%25E8%25A1%2597%25E9%2581%2593&S_ZCZJ=&basemcclsm=&S_ZZSIGN=hz&ghcomboid=&S_MCZZXS=%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8&clidsm=&xzqhwz=0&S_HYXL=7484&S_HYZL=7400&pripid=&S_PROLOC_CITY=330100&znspsign=0&ljmsign=2&csrftoken=&S_QYLXDL=11&S_SJQYUNISCID=&sbid=&ispt=Y&S_QYZTLX=01&S_GMLX=0&pri_pripid=&S_PROLOC_DISTRICT=330102&method=enterMczzws_zj&gzqsign=&nameZh=%25E9%259D%259E%25E8%2584%259A%25E5%2590%258E%25E8%25B7%259F&S_REGCAP=&S_PROLOC_PROVINCE=330000&IP=10.1.10.103&S_SJQYENTNAME=&ghopscope=&mcjbxx=S_PROLOC_PROVINCE_%3A330000_%2CS_PROLOC_CITY_%3A330100_%2CS_PROLOC_DISTRICT_%3A330102_%2CS_PROLOC_LOCATION_%3A330102016_%2CS_PROLOC_%3A%25E6%25B5%2599%25E6%25B1%259F%25E7%259C%2581%25E6%259D%25AD%25E5%25B7%259E%25E5%25B8%2582%25E4%25B8%258A%25E5%259F%258E%25E5%258C%25BA%25E7%25AC%2595%25E6%25A1%25A5%25E8%25A1%2597%25E9%2581%2593_%2CS_QYZTLX_%3A01_%2CS_REGCAP_%3A_%2CS_HYDL_%3AM_%2CS_HYZL_%3A7400_%2CS_HYXL_%3A7484_%2CS_GMLX_%3A0_%2CS_TRADPINY_%3AFEIJIAOHOUGEN_%2CS_ENTTRA_%3A%25E9%259D%259E%25E8%2584%259A%25E5%2590%258E%25E8%25B7%259F_%2CS_QYLXDL_%3A11_%2CS_ENTTYPE_%3A1100_%2CS_ZCZJ_%3A_%2CS_RJCZE_%3A_%2CS_CZE_%3A_%2CS_SJQYENTNAME_%3A_%2CS_SJQYUNISCID_%3A_%2CS_COMMITLETTER_%3A_%2CS_MCZZXS_%3A%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8_%2CS_OPSCOPE_%3A%25E5%25B7%25A5%25E7%25A8%258B%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25B4%25BB%25E5%258A%25A8_%2CS_JYFWBYHAND_%3A%25E5%25B7%25A5%25E7%25A8%258B%25E8%25AE%25BE%25E8%25AE%25A1%25E6%25B4%25BB%25E5%258A%25A8_%2CS_MCHYSIGN_%3A1_%2CS_ISQZSP_%3Aundefined_%2CS_NAMEREGION_%3A%25E6%25B5%2599%25E6%25B1%259F_%2CS_NAMEINDUSTRY_%3A%25E5%25BB%25BA%25E7%25AD%2591%25E8%25AE%25BE%25E8%25AE%25A1%25E4%25BA%258B%25E5%258A%25A1%25E6%2589%2580_%2CS_BZSM_%3A_%2CS_ISPCOM_%3A2_%2CS_GRPNAME_%3A_%2CS_ITE_%3A0_%2CS_ITENAME_%3A_%2CS_ITEREGNO_%3A_%2CS_ZZSIGN_%3Ahz&name_id=&S_RJCZE=&zrzysx=&S_PROLOC_STREET=330102016&S_TRADPINY=FEIJIAOHOUGEN&S_ENTTYPE=1100&nameList=%25E6%25B5%2599%25E6%25B1%259F%2C%25E9%259D%259E%25E8%2584%259A%25E5%2590%258E%25E8%25B7%259F%2C%25E5%25BB%25BA%25E7%25AD%2591%25E8%25AE%25BE%25E8%25AE%25A1%25E4%25BA%258B%25E5%258A%25A1%25E6%2589%2580%2C%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%2C%25E6%25B5%2599%25E6%25B1%259F%25E9%259D%259E%25E8%2584%259A%25E5%2590%258E%25E8%25B7%259F%25E5%25BB%25BA%25E7%25AD%2591%25E8%25AE%25BE%25E8%25AE%25A1%25E4%25BA%258B%25E5%258A%25A1%25E6%2589%2580%25E6%259C%2589%25E9%2599%2590%25E5%2585%25AC%25E5%258F%25B8%3B&S_HYDL=M&S_CZE=";

        System.out.println(formData);
        // 注意：这里我们仍然将参数放在查询字符串中，尽管这是一个POST请求
        // 如果API设计为接受查询参数，则这是可以的；否则，应考虑将参数放在请求体中
        Response response = RestAssured.given()
//                .body(formData)
                .cookies(cookies)
//                .header("Content-Type", "multipart/form-data; boundary=----WebKitFormBoundarySOV73YndgGznlxaB")
                .baseUri("http://10.1.10.141:9031")
                .get(formData); // 假设这里有一个有效的CSRF Token或它是不必要的

        int statusCode = response.getStatusCode();
//        String body = response.getBody().asString();
        String responseBody = response.getBody().asString();
//        System.out.println("Response Body: " + responseBody);


        System.out.println("Status Code: " + statusCode);
//        int chunkSize = 1000; // 每次打印的字符数
//        for (int start = 0; start < body.length(); start += chunkSize) {
//            int end = Math.min(body.length(), start + chunkSize);
//            System.out.println(body.substring(start, end));
//        }

//        if (body != null) {
//            System.out.println("Response Body: " + body);
//        } else {
//            System.out.println("Response Body is null");
//        }


        return statusCode;

    }
}
